#include "StationCmd.h"
#include <string>
#include <cassert>
#include <iostream>

using namespace std;


StationCmd::StationCmd(string commandText) : Command(){
	 setCommand(commandText);
	 nextStation = NULL;
	// Error	1	error LNK2019: unresolved external symbol "public: void __thiscall ICommand::setCommand(class std::basic_string<char,struct 
		// std::char_traits<char>,class std::allocator<char> >)" (?setCommand@ICommand@@QAEXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
		// referenced in function "public: __thiscall StationCmd::StationCmd(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)"
		// (??0StationCmd@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
	// _cmd = commandText;
}

StationCmd::StationCmd(string curStation, string nextStation){
	setCommand(curStation);
	this->nextStation = new StationCmd(nextStation);
}
// class MyException;
void StationCmd::execute(){
	/*cout << "Current Staion: " << _cmd;
	nextStation == NULL ? cout << ", This is the termination" : cout << ", NextStation: " << nextStation->getCommand();
	cout << endl;*/

	cout << "Current Staion: " << _cmd;
	try{
		if(nextStation == NULL){
			/*MyException exception("\nTest Exception");
			throw exception;*/
			// throw new MyException("\nTest Exception"); // catch(MyException *err) If using like this, we should delete err in catch block, or maybe cause memeory overflow
			throw MyException("\nTest Exception");			
		}
		cout << ", NextStation: " << nextStation->getCommand() << endl;
		throw new MyException("Test the 'catch(...)' block");
	}catch(MyException err){
		err.print();
		cout << "This is the termination" << endl;		
	}
	catch(...){
		cout << "Catch all of the exceptions with catch(...) block!! -- This block can be used as finally block to release the resource the application allocated." << endl;
	}
}
